﻿@model IEnumerable<Core.Models.Post>
@using System.Web.Mvc;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout_Admin.cshtml";
}
@helper Truncate(string input, int length)
    {
        input = Server.HtmlDecode(input);
        if (input.Length <= length)
        {
    @Html.Raw(input)
        }
        else
        {
    @Html.Raw(input.Substring(0, length)) <text>...</text>
        }
}
@foreach (var item in Model)
{ 
    <div class="panel panel-success">
        <div class="panel-heading">
            <h3 class="panel-title">
                @Html.ActionLink(@item.Title, "Details", "Post", new { id = @item.Id }, "")</h3>
        </div>
        <div class="panel-body">
            <div class="panel-body-createddate">
                @Html.DisplayFor(model => item.CreatedDate)
            </div>
            <div class="panel-body-content">
                @Truncate(item.Content, 500)
            </div>
            <div class="panel-body-actionlink">
                @Html.ActionLink("Edit", "Edit", "Post", new { id = @item.Id }, "") |
                @Html.ActionLink("Delete", "Delete", "Post", new { id = @item.Id }, "")
            </div>
        </div>
    </div>
}
<div id="page-list">
    <ul class="pagination">
        @{
            int start = 1, end = 1;

            end = ViewBag.PageIndex > ViewBag.PageSizeRender ? ViewBag.PageIndex : ViewBag.PageSizeRender;
            end = end < ViewBag.TotalPage ? end : ViewBag.TotalPage;
            start = end - ViewBag.PageSizeRender;
            if (start >= 1)
            {
            <li>
                @Html.ActionLink("Previous", "Index", "Post", new { pageIndex = start }, "")
            </li>
            }
            for (int i = (start < 1 ? 1 : (start + 1)); i <= end; i++)
            {
                var cssclass = "";
                if (i == ViewBag.PageIndex)
                {
                    cssclass = "current-page-index";
                }
            <li class="@cssclass">
                @Html.ActionLink(i.ToString(), "Index", "Post", new { pageIndex = i }, "")
            </li>
            
            }
            if (end < ViewBag.TotalPage)
            {
            <li>
                @Html.ActionLink("Next", "Index", "Post", new { pageIndex = end + 1 }, "")
            </li>
            }
        }
    </ul>
</div>
